package com.example.springbootmybatiszuoye.controller;

import com.example.springbootmybatiszuoye.pojo.Emp;
import com.example.springbootmybatiszuoye.service.EmpService;
import com.example.springbootmybatiszuoye.utils.Result;

import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * EmpController
 *
 * @author liliudong
 * @version 1.0
 * @description
 * @date 2023/4/28 12:59
 */
@RestController

public class EmpController {

@Autowired
    private  EmpService empService;

    /**
     * 这里采用了构造器注入法
     *
     * @param empService
     */
//    public EmpController(EmpService empService) {
//        this.empService = empService;
//    }

    /**
     * 新增一个EMP员工
     *
     * @param emp emp
     * @return void
     */
    @RequestMapping("/add")

    public Result insertEmp(@RequestBody Emp emp) {

        empService.insertEmp(emp);
        return Result.success();
    }

    /**
     *根据id删除员工
     * @param id
     * @return
     */

    @RequestMapping("/del/{id}")
    public Result deleteById(@PathVariable String id) {
        empService.deleteById(id);
        return Result.success();
    }

    /**
     *
     * @param emp
     * @return
     */
    @RequestMapping("/updateById")
    public Result updateById(@RequestBody Emp emp) {
        empService.updateById(emp);
        return Result.success();

    }

    /**
     * 查看所有员工集合
     * @return
     */

    @RequestMapping("/list")
    public Result selectEmp() {
        List<Emp> list = empService.selectEmp();

        return Result.success(list);

    }

    /**
     * 根据id查看员工信息
     * @param id
     * @return
     */

    @RequestMapping("/info/{id}")
    public Result selectById(@PathVariable String id) {
        Emp emp = empService.selectById(id);
        return Result.success(emp);

    }

}
